<?php
// $Id$

/**
 * Controller_Admin_Callergroup 控制器
 */
class Controller_Admin_Callergroup extends Controller_Abstract
{

	function _format_appendSql()
	{
		if (isset($_SESSION['acct']))
		{
			if ($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1)
			{
			//为管理
				//$append['']
				//$append['admin_id'] = $_SESSION['acct']['id'];
				$append = array();
			}else
			{
				//$append['admin_id'] = $_SESSION['acct']['admin_id'];
				$append['admin_id'] = Acct::_get_have_acctid($_SESSION['acct']['id'], $_SESSION['acct']['admin_id']);
			}
		}
		return $append;
	}
	function actionIndex()
	{
        $this->union_table = Callergroup::meta();
        $this->lists($this->_format_appendSql());
	}
	function actionlist()
	{
		$this->union_table = Callerlist::meta();
		$this->lists(array('callergroup_id'=>intval($this->_context->callergroup_id)));
	}
	function actionlistadd()
	{
		$this->union_table = Callerlist::meta();
		//ini_set('allow_call_time_pass_reference', true); //开启引用？
		$handle = new helper_autoinsert($this->union_table);
		$form = new Form_callergroup_listadd(url($this->_context->controller_name.'/'.$this->_context->action_name));
		$result = $handle->add($form, 'id',$_GET);
		
		if ($this->_context->isGET())
		{
			$this->_view['form'] = $result;
			$this->_viewname = '../form/add';
		}else {
			Syslog::logs('编辑主叫号码:'.$_POST['caller'].',ID:'.$_POST['id']);
			return call_user_func_array(array($this,$handle->status),array($result));
		}
	}
	
	function actionadd()
	{
		$this->union_table = Callergroup::meta();
		//ini_set('allow_call_time_pass_reference', true); //开启引用？
		$handle = new helper_autoinsert($this->union_table);
		$form = new Form_callergroup_add(url($this->_context->controller_name.'/'.$this->_context->action_name));
		$result = $handle->add($form, 'id',$_GET);
		
		if ($this->_context->isGET())
		{
			
			
			$result->element('agent_id')->value = Acct::get_curId();
			
			$this->_view['form'] = $result;
			$this->_viewname = '../form/add';
		}else {
			Syslog::logs('编辑主叫号码池:'.$_POST['callergroup_name'].',ID:'.$_POST['id']);
			return call_user_func_array(array($this,$handle->status),array($result));
		}
	}
	function actiondel()
	{
		Syslog::logs('删除主叫号码池,ID:'.$this->_context->ids);
		$this->union_table = Callergroup::meta();
		$this->delete(array('id'=>$this->_context->ids));
		
	}
	function actionlistdel()
	{
		Syslog::logs('删除主叫号码,ID:'.$this->_context->ids);
		$this->union_table = Callerlist::meta();
		$this->delete(array('id'=>$this->_context->ids));
		
	}
}


